package com.design01_builder.pattern01_singleton;

/**
 * @ClassName Singleton05
 * @Description 静态内部类
 *      懒汉式,静态加载,根据惊天内部类的形式
 *      特性:静态类使用到了才会创建
 * @Author zhangjunhao
 * @DATE 2023/8/31 23:13
 */
public class Singleton05 {

    public Singleton05() {
        //避免反射访问
        if (Singleton05_2.singleton05 != null){
            throw new RuntimeException("不允许非法访问");
        }

    }


    private static class Singleton05_2{

        private static Singleton05 singleton05 = new Singleton05();


    }

    public static Singleton05 getInstance(){
        return  Singleton05_2.singleton05;
    }

}
